package com.zkingsoft.actions.admin;

import com.zkingsoft.services.PaymentinfoService;
import com.zkingsoft.services.SchoolmanageService;
import javax.annotation.Resource;
import com.zkingsoft.actions.common.BaseController;
import org.springframework.stereotype.Controller;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.plugin.util.WebUtil;

import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.model.Paymentinfo;
import com.zkingsoft.model.Schoolmanage;
import org.springframework.web.bind.annotation.RequestMapping;
import com.zkingsoft.anotations.RemoveRequestToken;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.exception.GlobleException;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2017-06-13 14:49
 */
@Controller
@RequestMapping(value = "admin/schoolmanage")
public class SchoolmanageController extends BaseController{

	@Resource
	private SchoolmanageService currentService;
	
	@Resource
	private PaymentinfoService paymentinfoService;
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(Schoolmanage schoolmanage, PaginationVO pageVo) {
		return showList(currentService, schoolmanage, pageVo);
	}
   	
	/**
	 * 新增或者修改页面
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(Schoolmanage schoolmanage) {
		Paymentinfo paymentinfo = paymentinfoService.findBysId(schoolmanage.getsId());
		// 判断该学生是否有交学费
		if (paymentinfo == null) {
			throw new GlobleException("该学生没有交学费");
		}
		if (schoolmanage.getUcId() != null) {
			return modify(currentService, schoolmanage, "院校管理");
		} else {
			return add(currentService, schoolmanage, "院校管理");
		}
	}
	
   	/**
	 * 进入修改界面
	 */   
	@SaveRequestToken
   	@RequestMapping(value = "/editForm")
	public String editForm(Long id) {
		Schoolmanage schoolmanage;
		if (id != null) {
			schoolmanage = currentService.findById(id);
			WebUtil.getRequest().setAttribute("obj", schoolmanage);
		}
		return "admin/schoolmanage-form";
	}
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(currentService, keys);
	}
  
 	/**
 	 *查询对象 
 	 * */
 	@RequestMapping(value = "/findModel")
 	public @ResponseBody AjaxResult findModel(Schoolmanage schoolmanage){
 		AjaxResult result = new AjaxResult(AjaxResult.STATUS_OK, null, null,currentService.findByModel(schoolmanage),null);
		return result;
 	}
}